package cn.tedu.ivos.audit.controller;

import cn.tedu.ivos.audit.pojo.dto.AuditParam;
import cn.tedu.ivos.audit.pojo.dto.AuditQuery;
import cn.tedu.ivos.audit.pojo.vo.AuditVO;
import cn.tedu.ivos.audit.service.AuditService;
import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.base.response.StatusCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/v1/audit")
public class AuditController {
    @Autowired
    private AuditService auditService;
    @GetMapping("/select")
    public JsonResult selectAudit(AuditQuery auditQuery) {
        log.debug("开始处理查询审批单请求,参数:{}",auditQuery);
        List<AuditVO> list = auditService.selectAudit(auditQuery);
        return JsonResult.ok(list);
    }
    @PostMapping("/update")
    public JsonResult passAudit(@RequestBody AuditParam auditParam) {
        log.debug("开始处理通过审批请求,参数:{}",auditParam);
        int rows = auditService.updateAudit(auditParam);
        if (rows != 1) {
            return new JsonResult(StatusCode.OPERATION_FAILED, "审批失败");
        }
        return JsonResult.ok();
    }

}
